package com.chinatechstar.decis.controller;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chinatechstar.decis.entity.DecisEconWater;
import com.chinatechstar.decis.service.DecisEconWaterService;
import com.chinatechstar.component.commons.result.ActionResult;
import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.result.ResultBuilder;
import com.chinatechstar.component.commons.utils.ExcelUtils;
import com.chinatechstar.component.commons.validator.InsertValidator;
import com.chinatechstar.component.commons.validator.UpdateValidator;

/**
 * 经济效益评价-自然月水处理成本 的控制层
 *
 * @author Rei
 */
@Api(value = "经济效益评价-自然月水处理成本 的控制层", tags = {"经济效益评价-自然月水处理成本"})
@RestController
@RequestMapping("/deciseconwater")
public class DecisEconWaterController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private DecisEconWaterService decisEconWaterService;

    /**
     * 查询 经济效益评价-自然月水处理成本 所有数据
     *
     * @return ListResult<Object>
     */
    @ApiOperation(value = "查询 经济效益评价-自然月水处理成本 所有数据", tags = {"经济效益评价-自然月水处理成本"})
    @GetMapping(path = "/findDecisEconWaterAll")
    public ListResult<Object> findDecisEconWaterAll() {
        List<DecisEconWater> list = decisEconWaterService.findDecisEconWaterAll();
        return ResultBuilder.buildListSuccess(list);
    }

    /**
     * 查询 经济效益评价-自然月水处理成本 分页
     *
     * @param currentPage 当前页数
     * @param pageSize    每页记录数
     * @param name        名称
     * @param sorter      排序
     * @return ListResult<Object>
     */
    @ApiOperation(value = "查询 经济效益评价-自然月水处理成本 分页", tags = {"经济效益评价-自然月水处理成本"})
    @GetMapping(path = "/findDecisEconWaterByCondition")
    public ListResult<Object> findDecisEconWaterByCondition(@RequestParam(name = "currentPage", required = false, defaultValue = "1") Integer currentPage,
                                                            @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                            @RequestParam(name = "name", required = false) String name,
                                                            @RequestParam(name = "sorter", required = false) String sorter) {
        Map<String, Object> data = decisEconWaterService.findDecisEconWaterByCondition(currentPage, pageSize, name, sorter);
        return ResultBuilder.buildListSuccess(data);
    }

    /**
     * 根据查询条件导出 经济效益评价-自然月水处理成本
     *
     * @param response 响应对象
     * @param paramMap 参数Map
     */
    @ApiOperation(value = "根据查询条件导出 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PostMapping(path = "/exportDecisEconWater")
    public void exportDecisEconWater(HttpServletResponse response, @RequestParam Map<String, Object> paramMap) {
        try {
            List<String> headList = Arrays.asList("ID", "");
            List<LinkedHashMap<String, Object>> dataList = decisEconWaterService.findDecisEconWaterForExcel(paramMap);
            ExcelUtils.exportExcel(headList, dataList, "导出信息", response);
        } catch (Exception e) {
            logger.warn(e.toString());
        }
    }

    /**
     * 根据主键ID查询 经济效益评价-自然月水处理成本 数据
     *
     * @param id ID
     * @return ActionResult
     */
    @ApiOperation(value = "根据主键ID数据查询 经济效益评价-自然月水处理成本 数据", tags = {"经济效益评价-自然月水处理成本"})
    @GetMapping(path = "/findDecisEconWaterById")
    public ActionResult findDecisEconWaterById(@RequestParam(name = "id") Long id) {
        DecisEconWater data = decisEconWaterService.findDecisEconWaterById(id);
        return ResultBuilder.buildActionSuccess(data);
    }

    /**
     * 根据主键ID数组查询 经济效益评价-自然月水处理成本 数据
     *
     * @param ids ID数组
     * @return ActionResult
     */
    @ApiOperation(value = "根据主键ID数组查询 经济效益评价-自然月水处理成本 数据", tags = {"经济效益评价-自然月水处理成本"})
    @GetMapping(path = "/findDecisEconWaterByIds")
    public ListResult<Object> findDecisEconWaterByIds(@RequestParam(name = "ids") Long[] ids) {
        List<DecisEconWater> list = decisEconWaterService.findDecisEconWaterByIds(ids);
        return ResultBuilder.buildListSuccess(list);
    }

    /**
     * 新增或编辑 经济效益评价-自然月水处理成本
     *
     * @param decisEconWater 经济效益评价-自然月水处理成本 实体
     * @return ActionResult
     */
    @ApiOperation(value = "新增或编辑 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PostMapping(path = "/editDecisEconWater")
    public ActionResult editDecisEconWater(@Validated(InsertValidator.class) @RequestBody DecisEconWater decisEconWater) {
        decisEconWaterService.editDecisEconWater(decisEconWater);
        return ResultBuilder.buildActionSuccess();
    }

    /**
     * 批量新增 经济效益评价-自然月水处理成本
     *
     * @param decisEconWaters 经济效益评价-自然月水处理成本 实体数组
     * @return ActionResult
     */
    @ApiOperation(value = "批量新增 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PostMapping(path = "/addDecisEconWaters")
    public ActionResult addDecisEconWaters(@Validated(InsertValidator.class) @RequestBody List<DecisEconWater> decisEconWaters) {
        decisEconWaterService.insertDecisEconWaters(decisEconWaters);
        return ResultBuilder.buildActionSuccess();
    }

    /**
     * 编辑 经济效益评价-自然月水处理成本
     *
     * @param decisEconWater 经济效益评价-自然月水处理成本 实体
     * @return ActionResult
     */
    @ApiOperation(value = "编辑 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PutMapping(path = "/updateDecisEconWater")
    public ActionResult updateDecisEconWater(@Validated(UpdateValidator.class) @RequestBody DecisEconWater decisEconWater) {
        decisEconWaterService.updateDecisEconWater(decisEconWater);
        return ResultBuilder.buildActionSuccess();
    }

    /**
     * 批量编辑 经济效益评价-自然月水处理成本
     *
     * @param decisEconWaters 经济效益评价-自然月水处理成本 实体数组
     * @return ActionResult
     */
    @ApiOperation(value = "批量编辑 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PostMapping(path = "/updateDecisEconWaters")
    public ActionResult updateDecisEconWaters(@Validated(UpdateValidator.class) @RequestBody List<DecisEconWater> decisEconWaters) {
        decisEconWaterService.updateDecisEconWaters(decisEconWaters);
        return ResultBuilder.buildActionSuccess();
    }

    /**
     * 删除 经济效益评价-自然月水处理成本
     *
     * @param id ID
     * @return ActionResult
     */
    @ApiOperation(value = "根据主键ID删除 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PostMapping(path = "/deleteDecisEconWaterById")
    public ActionResult deleteDecisEconWaterById(@RequestParam(name = "id") Long id) {
        decisEconWaterService.deleteDecisEconWaterById(id);
        return ResultBuilder.buildActionSuccess();
    }

    /**
     * 删除 经济效益评价-自然月水处理成本
     *
     * @param ids ID数组
     * @return ActionResult
     */
    @ApiOperation(value = "根据主键ID数组批量删除 经济效益评价-自然月水处理成本", tags = {"经济效益评价-自然月水处理成本"})
    @PostMapping(path = "/deleteDecisEconWaterByIds")
    public ActionResult deleteDecisEconWaterByIds(@RequestParam(name = "id") Long[] ids) {
        decisEconWaterService.deleteDecisEconWaterByIds(ids);
        return ResultBuilder.buildActionSuccess();
    }

}
